package com.leetcode.solution.s9x;

import com.leetcode.solution.model.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class InorderTraversal94 {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(1, null, new TreeNode(2, new TreeNode(3), null));
//        TreeNode root = null;
        List<Integer> result = new InorderTraversal94().inorderTraversal(root);
        for (Integer integer : result) {
            System.out.println(integer);
        }
    }

    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> result = new ArrayList<>();
        inorderTraversal(root, result);

        return result;
    }

    private void inorderTraversal(TreeNode root, List<Integer> result) {
        if (root == null) {
            return;
        }

        inorderTraversal(root.left, result);
        result.add(root.val);
        inorderTraversal(root.right, result);

    }
}
